
***Limpieza de datos
clear all
set more off
set trace off
set tracedepth 1 

global ipvOutcomes any_violence phy_violence psy_violence // cont_behavior arguments 
global dumOutcomes dAny dArgs dCont dPsy dPhy dPsyPhy

global incOutcomes  income_hh log_income_hh ihs_income_hh income_dummy income_woman_mid income_man_mid  days_out  

global mentalHealth anxiety sentimental loneliness rage raise_voice violence









/*---------------------------------------------------------------------------
----- Esttab globals
----------------------------------------------------------------------------*/

global joinMgroupSetting 	prefix(\multicolumn{@span}{c}{) suffix(}) ///
	span erepeat(\cmidrule(lr){@span})

	
	


global stars_settings 	 star(* 0.10 ** 0.05 *** 0.01)   se(a3) b(a3) ///

global regOutputFormattingHelp 		noomitted ///
		varwidth(35) ///
		compress   ///
		$stars_settings  ///
		label nobaselevels interaction("$\times$") ///
		substitute(\_ _ "=1" "" ) 
		
		
global regOutputSettings $regOutputFormattingHelp numbers replace
global regOutputSettNoNumb $regOutputFormattingHelp nonumbers


global incomeLabs   		mtitles("Levels" "Log" "$>$0" "IHS" "Out" "$>$0" ) ///
		mgroups("Income" "Income" "Income" "Income" "Days" "Alcohol", pattern( 1 1 1 1 1 1  ) span) 

// you need the special cell command in the latex file \newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
// which is copied from https://tex.stackexchange.com/questions/2441/how-to-add-a-forced-line-break-inside-a-table-cell/19678#19678
global tabSettings 	booktabs	prehead( \begin{tabular}{l*{@M}{c}} \toprule\toprule) postfoot(\bottomrule \bottomrule \end{tabular})   

global sector_clusters s( ymean N   ,label( "Outcome Mean (2019)"   "Observations"   ))
global district_clusters s( ymean N N_clust1  ,label( "Outcome Mean (2019)"   "Observations" "Districts"  ))


cap program drop addScalars
program define addScalars
	//syntax namelist(max=1)
	//qui: estadd ysumm 
	preserve
		qui: keep if year == 2019
		qui: estadd ysumm
	restore

	
	
	quietly estadd local fixed_dis "Yes", replace
end	

**************************************************************************
****************** OPENING DATA SET
**************************************************************************

//anxiety sentimental loneliness rage raise_voice violence

use "$data_folder/NBER_HPI_PANEL_with_bartick.dta", clear

xtset id_cases year
sort id_cases year

//keep hpi sample that answered both in person and our phone survey
keep if sample == 2

//create var with inei as baseline and phone as later 

foreach set in 5678 3 {

	gen ipv`set'_ineifilled =  ipv`set'_inei 
	replace ipv`set'_ineifilled = ipv`set'_reg if year != 2019
	
	gen dumipv`set'_ineifilled =  ipv`set'_ineifilled > 0 if ipv`set'_ineifilled != . 
	gen dumipv`set'_reg =  ipv`set'_reg > 0 if ipv`set'_reg != . 
	
	
	gen diff`set' = ipv`set'_reg  - ipv`set'_inei  if year == 2019
	
	
}

tab dumipv3_ineifilled dumipv3_reg if year ==2019
tab dumipv5678_ineifilled dumipv5678_reg if year ==2019


la var ipv5678_ineifilled "\specialcell{With Baseline Value\\Physical}"
la var ipv5678_reg "\specialcell{With Recalled Value\\Physical}"

la var ipv3_ineifilled "\specialcell{With Baseline Value\\Psychological}"
la var ipv3_reg "\specialcell{With Recalled Value\\Psychological}"


la var dumipv5678_ineifilled "\specialcell{With Baseline Value\\Physical $>$ 0}"
la var dumipv5678_reg "\specialcell{With Recalled Value \\Physical $>$ 0}"

la var dumipv3_ineifilled "\specialcell{With Baseline Value\\Psychological $>$ 0}"
la var dumipv3_reg "\specialcell{With Recall Value\\Psychological $>$ 0}"


la var diff5678 "\specialcell{Recall Error\\Physical}"
la var diff3 "\specialcell{Recall Error\\Psychological}"
 

foreach set in 5678 3 {

	//inei 
	eststo occLin_v2`set'_duminei:  reghdfe dumipv`set'_ineifilled (post_aprilmay post_julaug)##c.pct_chng_wgt_v2, a(id_cases ) cluster(sector22) 
	addScalars
	//our sample 
	eststo occLin_v2`set'_dumreg:  reghdfe dumipv`set'_reg (post_aprilmay post_julaug)##c.pct_chng_wgt_v2, a(id_cases ) cluster(sector22) 
	addScalars
	 
	eststo diffreg`set' : reghdfe diff`set' pct_chng_wgt_v2, noabsorb cluster(sector22) 
	estadd ysumm 
}



//stacking to test coeffs across specs 

preserve
	tempfile data 
	sa `data'

	append using `data', gen(appended)

	foreach set in 5678 3 {
		gen stacked`set' = dumipv`set'_ineifilled
		replace  stacked`set' = dumipv`set'_reg if appended == 1

		
	}


	eststo stacked5678: reghdfe stacked5678 ((post_aprilmay post_julaug)##c.pct_chng_wgt_v2)#appended, a(id_cases ) cluster(sector22) 
	eststo stacked3: reghdfe stacked3 ((post_aprilmay post_julaug)##c.pct_chng_wgt_v2)#appended, a(id_cases ) cluster(sector22) 


	estimates restore  stacked5678
	test 1.post_aprilmay#1.appended#c.pct_chng_wg = 1.post_aprilmay#0.appended#c.pct_chng_wg  

	estimates restore  stacked3
	test 1.post_aprilmay#1.appended#c.pct_chng_wg = 1.post_aprilmay#0.appended#c.pct_chng_wg  
restore

 



**** Table A9 **** 
esttab  diffreg5678 diffreg3  ///
	using "$tex_folder/recall_error_shock_ols.tex" ///
	, ///
	s( ymean N   ,label( "Error Mean"  ))  ///
	$tabSettings  $regOutputSettings  keep(*pct_chng_wgt_v2* )


lab def dumPhysBSlabel 0 "\specialcell{Baseline Value\\Physical = 0}" 1 "\specialcell{Baseline Value\\Physical $>$ 0}", modify
lab def dumPhysRElabel 0 "\specialcell{Recalled Value\\Physical = 0}" 1 "\specialcell{Recalled Value\\Physical $>$ 0}", modify


lab def dumPsychBSlabel 0 "\specialcell{Baseline Value\\Psychological = 0}" 1 "\specialcell{Baseline Value\\Psychological $>$ 0}", modify
lab def dumPsychRElabel 0 "\specialcell{Recalled Value\\Psychological = 0}" 1 "\specialcell{Recalled Value\\Psychological $>$ 0}", modify


label values dumipv5678_inei dumPhysBSlabel
label values dumipv5678_reg dumPhysRElabel

label values dumipv3_inei dumPsychBSlabel
label values dumipv3_reg dumPsychRElabel


**** Table A7 **** 

estpost tabulate dumipv5678_inei dumipv5678_reg if year == 2019
esttab . ///
	using "$tex_folder/recall_tab_physical.tex" ///	
	, ///
	unstack noobs nonumbers ///
	varlabels(`e(labels)', blist(Total "\midrule ")) ///
	eqlabels(`e(eqlabels)') ///
	replace  booktabs ///
	prehead( \begin{tabular}{l*{@E}{c}} \toprule\toprule)  /// Notive the @E
	postfoot(\bottomrule \bottomrule \end{tabular})

**** Table A8 **** 
estpost tabulate dumipv3_inei dumipv3_reg if year == 2019
esttab . ///
	using "$tex_folder/recall_tab_psychol.tex" ///	
	, ///
	unstack noobs nonumbers ///
	varlabels(`e(labels)', blist(Total "\midrule ")) ///
	eqlabels(`e(eqlabels)') ///
	replace  booktabs ///
	prehead( \begin{tabular}{l*{@E}{c}} \toprule\toprule)  /// Notive the @E
	postfoot(\bottomrule \bottomrule \end{tabular})
